package com.vortex.cloud.sample.easyexcel.kuangshen.poi.write;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime;

import java.io.FileOutputStream;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-10-15 周五
 * @time 10:53
 * @description
 */
public class WriteExcelTest07 {
    public static void main(String[] args) throws Exception {
        String PATH = "H:\\fuTaiPorjects\\backend\\hw-clouc-sample-easyExcel";

        //1-创建一个工作簿 07
        Workbook workbook = new XSSFWorkbook();
        //2-创建一个工作表
        Sheet sheet = workbook.createSheet("王林观众统计表");

        //3-创建一个行 (1,1)
        Row row1 = sheet.createRow(0);

        //4-创建一个单元格
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("今日新增迷妹");

        //(1,2)
        Cell cell12 = row1.createCell(1);
        cell12.setCellValue("666");

        //创建第二行 (2,1)
        Row row2 = sheet.createRow(1);
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("统计时间");

        //创建第二行 (2,2)
        Cell cell22 = row2.createCell(1);

        String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
        cell22.setCellValue(time);


        //生成一张表 （IO流） 07版本就是使用 xlsx 结尾
        FileOutputStream fileOutputStream = new FileOutputStream(PATH + "王林观众统计表07.xlsx");
        workbook.write(fileOutputStream);

        //关闭流
        fileOutputStream.close();

        System.out.println("文件生成完毕！！！");

    }
}
